package org.vectrics.recruiter.struts.cv;

import javax.servlet.jsp.JspException;

import org.apache.log4j.Logger;
import org.vectrics.cv.Studies;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.struts.Request;
import org.vectrics.struts.VectricsActionData;
import org.vectrics.struts.VectricsStrutsAction;

/**
 * @author pgoette.
 * 
 * Clase Action que muestra los datos personales para poder modificarlo. 
 */

public class ShowStudiesEditAction extends VectricsStrutsAction {
	private transient static Logger log = Logger.getLogger(ShowStudiesEditAction.class);
	
	@Override
	protected String doExecute(VectricsActionData actionData)
			throws JspException {
		log.info("ShowStudiesEditAction.doExecute() called");
		
		//super.doExecute(actionData);
		Long studiesId = null;
		Request request = actionData.getRequest();
	    if (request.getParameter("studiesId")!=null) {
	    	//Recuperar el studiesId pasado por parametro 
	    	studiesId = new Long(request.getParameter("studiesId"));
	    } else {
	    	return "failer";
	    }
		
	    StudiesForm studiesForm =((StudiesForm) actionData.getForm());
	    // Recupero el estudio con el id pasado por parametro.
		Studies studies= CoreServiceLocator.getPersonService().findStudiesById(studiesId);
		
		// Seteo los datos al formulario.
		studiesForm.setIdEstudio(studies.getId().toString());
		studiesForm.setLevel(studies.getLevel());
		studiesForm.setCareer(studies.getCareer());
		if (studies.getStudyType() != null) {
			studiesForm.setStudyType(studies.getStudyType().getId().toString());
		}
		if (studies.getUniversity() != null) {
			studiesForm.setUniversity(studies.getUniversity().getId().toString());
		}
		studiesForm.setSchool(studies.getSchool());
		studiesForm.setStatus(studies.getStatus());
		
		studiesForm.setStartYear(studies.getStartYear().toString());
		if (studies.getEndYear() != null) {
			studiesForm.setEndYear(studies.getEndYear().toString());
		}
		if (studies.getTotalSubjectsApproved() != null) {
			studiesForm.setTotalSubjectsApproved(studies.getTotalSubjectsApproved().toString());
		} else {
			studiesForm.setTotalSubjectsApproved("");
		}

	    return "success";
	}

}
